<template>
  <aside class="sidebar">
    <el-menu
      class="menu-nav"
      router
      :default-active="$route.path"
      text-color="#fff"
      background-color="#35495e"
      :collapse="isCollapse"
      unique-opened
    >
      <el-submenu :index="item.path" v-for="item in menuList" :key="item.id">
        <template slot="title">
          <i class="el-icon-menu"></i>
          <span>{{ item.menuName }}</span>
        </template>
        <el-menu-item
          v-for="subitem in item.children"
          :key="subitem.id"
          :index="subitem.path"
        >
          <i class="icon-item"></i>
          <span slot="title">{{ subitem.menuName }}</span>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </aside>
</template>

<script>
export default {
  name: "Sidebar",
  data() {
    return {
      menuList: []
    };
  },
  computed: {
    isCollapse() {
      return this.$store.state.collapse;
    }
  },
  methods: {
    // 获取用户菜单
    getRoutes() {
      const routes = JSON.parse(localStorage.getItem("routes"));
      this.menuList = routes;
    }
  },

  mounted() {
    this.getRoutes();
  }
};
</script>

<style lang="scss" scoped>
.sidebar {
  min-width: 64px;
  height: 100%;
  background-color: #35495e;

  & /deep/ .menu-nav:not(.el-menu--collapse) {
    width: 210px;
    min-height: 400px;
  }

  .icon-item::before {
    width: 8px;
    height: 8px;
    margin: 0 8px;
    display: inline-block;
    content: "";
    vertical-align: middle;
    border-radius: 50%;
    background-color: #fff;
  }
}
</style>
